package com.example.myfristapp;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    public static final String EXTRA_MESSAGE = "com.example.myfristapp.MESSAGE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        //找事件源
//        Button btn = findViewById(R.id.button);
//        //设置事件监听,采用匿名内部类实现监听事件处理
//        btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                sendMessage(v);
//            }
//        });
    }

    public void sendMessage(View v){
        Log.i("MyDebug","====响应按钮点击事件====");
        //构建意图,从MainActivity->DisplayActivity
        Intent intent = new Intent(this, DisplayMessageActivity.class);
        //获取文本框中的数据
        EditText editText = findViewById(R.id.editTextTextPersonName);
        String message = editText.getText().toString();
        //把数据附加到intent上
        intent.putExtra(this.EXTRA_MESSAGE,message);
        //执行意图
        startActivity(intent);
    }
}